package util

import (
	"fmt"
	"math/rand"
	"time"
)

// RandStringRunes 返回随机字符串
func RandStringRunes(n int) string {
	var letterRunes = []rune("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

	rand.Seed(time.Now().UnixNano())
	b := make([]rune, n)
	for i := range b {
		b[i] = letterRunes[rand.Intn(len(letterRunes))]
	}
	return string(b)
}

// GetTimeStr 获取当前日期字符串
func GetTimeStr(timestamp int64) string {
	timeObj := time.Unix(timestamp, 0)
	year := timeObj.Year()   //年
	month := timeObj.Month() //月
	day := timeObj.Day()     //日
	return fmt.Sprintf(`%d-%02d-%02d`, year, month, day)
}

// GetPreSeven 获取前七天日期
func GetPreSeven() (seven []string) {
	var timestamp int64
	timestamp = time.Now().Unix()
	//获取前七天的日期
	for i := 0; i < 7; i++ {
		//fmt.Println(getTimeStr(timestamp))
		seven = append(seven, GetTimeStr(timestamp))
		timestamp -= 86400
	}
	return
}
